package day02.annotation.service;

import day02.annotation.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * @author 夏焰波
 * @date 2020-08-21 2:10
 */

@Service
public class UserService {
    //@Autowired
    //@Qualifier("userRepositoryImpl")
    //private UserRepository userRepository;

    private UserRepository userRepository;

/*
    //推荐这种方式
    @Autowired
    @Qualifier("userRepositoryImpl")
    public void setUserRepository(UserRepository userRepository) {
        this.userRepository = userRepository;
    }*/

    @Autowired
    public void setUserRepository(@Qualifier("userRepositoryImpl")/*加在入参前*/UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    public void add() {
        System.out.println("UserService add...");
        userRepository.save();
    }
}
